package com.gs.front.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gs.core.model.UserModel;
import com.gs.core.service.UserService;


@Controller
@RequestMapping("/hello")
public class HelloController {
	
	@Autowired
	UserService userService;
	
	@RequestMapping("/say")
	ModelAndView home() {
		return new ModelAndView("NewFile");
	}

	@RequestMapping("/hh")
	String hello() {
		return "NewFile";
	}
	
	@RequestMapping("/getByid")
	String getByid( Model model   ,Long id ) {
		UserModel userModel = userService.findById(id);
		model.addAttribute("userModel",userModel);
		return "userModel";
	}
	
	@RequestMapping("/findAll")
	@ResponseBody
	List<UserModel> findAll(){
		return userService.findAll();
	}
	
	@RequestMapping("/getJsonUserModelById")
	@ResponseBody
	UserModel getJsonUserModelById( Long id ){
		return userService.findById(id);
	}

	
	
	@RequestMapping("/save")
	@ResponseBody
	String save() {
		userService.save();
		return "成功";
	}
	
}
